package com.tebiecloud.order.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tebiecloud.common.utils.DateUtils;
import com.tebiecloud.common.utils.StringUtils;
import com.tebiecloud.order.client.model.entity.OrderStats2;
import com.tebiecloud.order.server.service.OrderStats2Service;
import com.tebiecloud.common.model.ResultBody;
import com.tebiecloud.common.utils.ResultBodyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;

/**
 * 门店营销额统计 前端控制器
 * @author tebie
 * @date 2019-09-23
 */
@RestController
@RequestMapping("/orderstats2")
public class OrderStats2Controller {

    @Autowired
    private OrderStats2Service orderStats2Service;

    /**
     * 门店营销额统计列表
     * @param storeId
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("list")
    public ResultBody list(@RequestParam("storeId") long storeId,
                           @RequestParam(value = "page",defaultValue = "1",required = false) int page,
                           @RequestParam(value = "limit",defaultValue = "10",required = false) int limit) {
        // 按时间倒序
        QueryWrapper<OrderStats2> orderStats2QueryWrapper = new QueryWrapper<>();
        orderStats2QueryWrapper.eq("store_id",storeId);
        orderStats2QueryWrapper.orderByDesc("day");
        IPage<OrderStats2> orderStats2IPage = orderStats2Service.page(new Page<OrderStats2>(page,limit),orderStats2QueryWrapper);
        return ResultBodyUtils.ok(orderStats2IPage);
    }

    /**
     * 根据条件获取数据
     * @param storeId
     * @param year
     * @param month
     * @param day
     * @return
     */
    @PostMapping("info")
    public ResultBody info(@RequestParam("storeId") long storeId,
                           @RequestParam(value = "year",required = false) String year,
                           @RequestParam(value = "month",required = false) String month,
                           @RequestParam(value = "day",required = false) String day) {
        OrderStats2 orderStats2 = orderStats2Service.getStats2(storeId,year,month,day);
        return ResultBodyUtils.ok(orderStats2);
    }

}
